package org.deltaset.meta.faces;

import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 *
 * @author dmakariev
 */
class HistoryStack implements Serializable {

    private final Deque<AttributeContext> attributeContexts;

    public HistoryStack() {
        attributeContexts = new ArrayDeque<AttributeContext>();
    }
    
    boolean isEmpty(){
        return attributeContexts.isEmpty();
    }

    boolean hasPrevious() {
        final boolean isEmpty = attributeContexts.size() < 2;
        return isEmpty;
    }

    void push(final AttributeContext attributeContext) {
        final AttributeContext last = attributeContexts.peek();
        final boolean isTheSameAsCurrentLast = attributeContext.equals(last);
        if (false == isTheSameAsCurrentLast) {
            attributeContexts.push(attributeContext);
        }
    }

    AttributeContext previous() {
        attributeContexts.pop();
        return attributeContexts.peek();
    }
    
    AttributeContext current(){
        return attributeContexts.peek();
    }
}
